package com.example.liteflow.mysql;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.StopWatch;
import cn.hutool.core.date.TimeInterval;
import com.example.liteflow.mysql.model.TestModel;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.flow.LiteflowResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

@Component
public class LiteFlowCommand implements CommandLineRunner {

    private final Logger log = LoggerFactory.getLogger(this.getClass());

    @Resource
    private FlowExecutor flowExecutor;

    @Override
    public void run(String... args) throws Exception {
    

    
        TestModel t =new TestModel();
        t.setNum(10000);
        t.setStr("测试循环 + " +t.getNum());
        StopWatch watcht = new StopWatch();
        LiteflowResponse liteflowResponse = flowExecutor.execute2Resp("chainFile",null,t);
        for (int i = 0; i <10; i++) {
            watcht.start(i+" <- ");
            liteflowResponse = flowExecutor.execute2Resp("chainFile",null,t);
            watcht.stop();
        }
        
        System.out.println(" 只是为了预编译结果： "+watcht.prettyPrint(TimeUnit.MILLISECONDS));
        t.setMsg("");
    
        System.out.println("-------分割线-----------");
    
        StopWatch watch = new StopWatch();
        for (int i = 0; i <10; i++) {
            watch.start(i+"->");
            liteflowResponse = flowExecutor.execute2Resp("chainFile",null,t);
            watch.stop();
        }
       
        System.out.println("脚本耗时 wach： "+watch.prettyPrint(TimeUnit.MILLISECONDS));
    
    
    
        TestModel  t2 =new TestModel();
        t2.setNum(10000);
        t2.setStr("测试循环 + " +t2.getNum());
        StopWatch watch2 = new StopWatch();
        for (int i = 0; i <10; i++) {
            watch2.start(i+"<-");
            liteflowResponse = flowExecutor.execute2Resp("chain2",null,t2);
            watch2.stop();
        }
        System.out.println("java耗时 wach2： "+ watch2.prettyPrint(TimeUnit.MILLISECONDS));
//
        
    

    }
}
